package com.test;

public class JavaAbstract {
    //Lev 1
    static class Food {
        @Override
        public String toString() {
            return getClass().getName();
        }
    }

    //Lev 2
    static class Fruit extends Food {
    }

    static class Meat extends Food {
    }

    //Lev 3
    static class Apple extends Fruit {
    }

    static class Banana extends Fruit {
    }

    static class Pork extends Meat {
    }

    static class Beef extends Meat {
    }

    //Lev 4
    static class RedApple extends Apple {
    }

    static class GreenApple extends Apple {
    }

    public static void main(String[] args) {
        tag:
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j <= i; j++) {
                if (i + j == 5) {
                    System.out.println(i + " " + j);
                    break tag;
                }
            }
        }
        Plate<? extends Fruit> fruitPlate = new Plate<Fruit>(new Apple());
//        fruitPlate.set(new Fruit());
        System.out.println(fruitPlate.get().toString());

        Plate<? super Fruit> fruitParent = new Plate<Food>(new Banana());
        fruitParent.set(new GreenApple());

        Object object = fruitParent.get();
        System.out.println(object.toString());
    }

    static class Plate<T> {
        private T item;

        public Plate(T t) {
            item = t;
        }

        public void set(T t) {
            item = t;
        }

        public T get() {
            return item;
        }
    }

}
